package com.ruoyi.web.controller.eduManage;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.eduManage.domain.SysMailConfig;
import com.ruoyi.eduManage.service.ISysMailConfigService;
import com.ruoyi.eduManage.utils.EduDictUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统邮箱配置Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/eduManage/config")
public class SysMailConfigController extends BaseController
{
    @Autowired
    private ISysMailConfigService sysMailConfigService;

    /**
     * 查询系统邮箱配置列表
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysMailConfig sysMailConfig)
    {
        startPage();
        List<SysMailConfig> list = sysMailConfigService.selectSysMailConfigList(sysMailConfig);
        // 映射是否激活的字典文字
        for (SysMailConfig cfg : list) {
            if (cfg.getIsActive() != null) {
                cfg.setIsActiveName(EduDictUtils.getDictLabel("yes_or_no", String.valueOf(cfg.getIsActive())));
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出系统邮箱配置列表
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:export')")
    @Log(title = "系统邮箱配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysMailConfig sysMailConfig)
    {
        List<SysMailConfig> list = sysMailConfigService.selectSysMailConfigList(sysMailConfig);
        ExcelUtil<SysMailConfig> util = new ExcelUtil<SysMailConfig>(SysMailConfig.class);
        util.exportExcel(response, list, "系统邮箱配置数据");
    }

    /**
     * 获取系统邮箱配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysMailConfigService.selectSysMailConfigById(id));
    }

    /**
     * 新增系统邮箱配置
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:add')")
    @Log(title = "系统邮箱配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMailConfig sysMailConfig)
    {
        return toAjax(sysMailConfigService.insertSysMailConfig(sysMailConfig));
    }

    /**
     * 修改系统邮箱配置
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:edit')")
    @Log(title = "系统邮箱配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMailConfig sysMailConfig)
    {
        return toAjax(sysMailConfigService.updateSysMailConfig(sysMailConfig));
    }

    /**
     * 删除系统邮箱配置
     */
    @PreAuthorize("@ss.hasPermi('eduManage:config:remove')")
    @Log(title = "系统邮箱配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysMailConfigService.deleteSysMailConfigByIds(ids));
    }
}
